package com.jnks.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Ryo
 */

@AllArgsConstructor
public enum CommonStatusEnum {

    /**
     * 通用状态枚举
     */
    DISABLE("0", "停用", 0),
    ENABLE("1", "启用", 1),

    DELETED("-1", "删除", -1),
    POLICE_STATION("2", "派出所", 2);

    @Getter
    @Setter
    private String code;
    @Getter
    @Setter
    private String message;
    @Getter
    @Setter
    private Integer IntCode;

    public static CommonStatusEnum getByCode(String code) {
        if (null == code) {
            return null;
        }
        for (CommonStatusEnum status : CommonStatusEnum.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    /**
     * 转化枚举为Map,key为code, value为message
     *
     * @return
     */
    public static Map<String, String> convert2Map() {
        Map<String, String> map = new HashMap<String, String>();
        for (CommonStatusEnum status : CommonStatusEnum.values()) {
            map.put(status.getCode(), status.getMessage());
        }
        return map;
    }

}
